package javalearning.MultiThreads.news.day01;

public class Students {
    private int age;
    private int i;
    private
    String name;
    private
    boolean flag;

    public synchronized void get() {
        if (flag) {
            try {
                this.wait();
            } catch (InterruptedException e) {
            }
        }
        System.out.println(name + ", age = " + age + "岁");
        flag = false;
        this.notify();
    }

    public synchronized void set() {
        if (flag) {
            try {
                this.wait();
            } catch (InterruptedException e) {
            }
        }
        if (i % 2 == 0) {
            name = ("文競萱");
            age = (18);
        } else {
            name = ("朱友峰");
            age = (19);
        }
        i++;
        this.notify();
        flag = true;
    }


}
